package cn.ichiva.puppet.example.base.p1;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.impl.AbstractPuppetComponent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

/**
 * 条件渲染,事件绑定
 */
public class L7ActionComponent extends AbstractPuppetComponent {

    @FXML
    public StringProperty counter = new SimpleStringProperty("0");

    @Override
    public CharSequence render() {
        imports(VBox.class, Label.class, Button.class);
        return """
                <VBox>
                   <Label text="${counter}" />

                    <Button text="事件绑定" onAction="#add" />
                    <Button text="内联表达式绑定" onAction="${controller.sub()}" />
                </VBox>
                """;
    }

    @FXML
    void add(){
        int  i = Integer.parseInt(counter.get());
        counter.set("" + ++i);
    }

    public void sub(){
        int  i = Integer.parseInt(counter.get());
        counter.set("" + --i);
    }

}
